package com.sky.controller.admin;

import com.sky.constant.CommonConstant;
import com.sky.result.Result;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/admin/shop")
@Api(tags = "店铺相关接口")
@Slf4j
public class ShopController {
    @Autowired
    @Qualifier("redisTemplate")
    private RedisTemplate template;

    @GetMapping("/status")
    public Result<Integer> getStatus(){
        Integer status = (Integer) template.opsForValue().get(CommonConstant.SHOP_STATUS);
        if(status==null){
            template.opsForValue().set(CommonConstant.SHOP_STATUS,0);
            return Result.success(0);
        }
        return Result.success(status);
    }
    @PutMapping("/{status}")
    public Result getStatus(@PathVariable Integer status){
        Integer status1 = (Integer) template.opsForValue().get(CommonConstant.SHOP_STATUS);

        template.opsForValue().set(CommonConstant.SHOP_STATUS,status);

        return Result.success();
    }
}
